<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var person = {
            name: '奉先',
            // 如果sayName改为箭头函数，那么this指向window（指向的定义对象的对象）
            sayName: function () {
                console.log("person.this",this)
                console.log("person.this.name",this.name)
            },
            friend: {
                name: "袁浩哲",
                sayName: function () {
                    console.log(this)
                    console.log(this.name)
                },
                // 这里this也指向window
                sayName2: () => {
                    console.log(this)
                    console.log(this.name)
                }
            }
        }

        // 函数内部：this指向person
        // person.sayName();
        // person.friend.sayName();
        // person.friend.sayName2();

        class Student {
            name = "奉先";
            sayName() {
                console.log("Student.this",this);
                console.log("Student.this.name",this.name);
            };
            friend = {
                name: "罗佰君",
                sayName()  {
                    console.log("Student.friend.this",this);
                    console.log("Student.friend.this.name",this.name) ;
                },
                sayName2: () => {
                    console.log("Student.friend.this2",this);
                    console.log("Student.friend.this.name2",this.name); 
                },
               
            };
        }

        let stu = new Student();
        stu.sayName();
        // undefined
        stu.friend.sayName();
        // 奉先
        stu.friend.sayName2();
        


    </script>
</body>

</html>